﻿import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls 2.12
import QtMultimedia 5.14
import "../animation/practiceAnimation"

ApplicationWindow {
    width: 1200*dp
    height: 800*dp
    minimumWidth: 1200*dp
    minimumHeight: 800*dp
    title: "维护校正打靶动图窗口"
    property int onflag: 0
    onVisibleChanged: {
        if(visible){
            practiceCanvas.startAnimation()
        }else{
            practiceCanvas.stopAnimation()
        }
    }
    Column{
        anchors.fill: parent
        spacing: 0*dp
        Rectangle{
            width: parent.width
            height: parent.height-390*dp
            color: "#E0E6E9"
            PracticeCanvas{
                id: practiceCanvas
                anchors.centerIn: parent
                width: Math.min(parent.width, parent.height*1.4)
                height: Math.min(parent.height, parent.width * 0.8)
            }
            Text {
                id:timeid
                x:(parent.width-140*dp)/6*4+100*dp+(parent.width-140*dp)/6/2-30*dp
                width: 60*dp
                font.bold: true
                font.pointSize: 15
                y:parent.height-30*dp
                text: formatTime(remainingSeconds)
            }
        }
        Rectangle{
            width: parent.width
            height: 160*dp
            color: "#F0F0F0"
            Rectangle{
                x:20*dp
                y:10*dp
                width: (parent.width-140*dp)/6
                height: parent.height-20*dp
                color: onflag===1?"#E5F0FF":"white"
                CustomDoubleButton{
                    title: "吸取梭体"
                    name1: "打开"
                    name2: "关闭"
                    x:20*dp
                    y:10*dp
                    width: parent.width-40*dp
                    onBt1: {
                        CMaintenance.maintenanceAction(title+name1)
                    }
                    onBt2: {
                        CMaintenance.maintenanceAction(title+name2)
                    }
                }
                CustomButtonIcon{
                    id:visible1_1
                    button_icon: onflag===1?"qrc:/picture/wh_jianh.png":"qrc:/picture/wh_jiah.png"
                    width: 30*dp
                    height: 30*dp
                    x:parent.width/2-15*dp
                    y:100*dp
                    onReleased: {
                        if(button_icon==="qrc:/picture/wh_jiah.png"){
                            onflag=1
                        }else{
                            onflag=0
                        }
                    }
                }
            }
            Rectangle{
                x:(parent.width-140*dp)/6+40*dp
                y:10*dp
                width: (parent.width-140*dp)/6
                height: parent.height-20*dp
                CustomDoubleButton{
                    title: "梭体上靶"
                    name1: "上移"
                    name2: "下移"
                    x:20*dp
                    y:10*dp
                    width: parent.width-40*dp
                    onBt1: {
                        CMaintenance.maintenanceAction(title+name1)
                        CAnimationPractice.feedPortUp()
                    }
                    onBt2: {
                        CMaintenance.maintenanceAction(title+name2)
                        CAnimationPractice.feedPortDown()
                    }
                }
            }
            Rectangle{
                x:(parent.width-140*dp)/6*2+60*dp
                y:10*dp
                width: (parent.width-140*dp)/6
                height: parent.height-20*dp
                color: onflag===3?"#E5F0FF":"white"
                CustomDoubleButton{
                    title: "梭体组合运行"
                    name1: "一键进靶"
                    name2: "一键退靶"
                    x:20*dp
                    y:10*dp
                    width: parent.width-40*dp
                    onBt1: {
                        CMaintenance.maintenanceAction(title+name1)
                        CAnimationPractice.oneButtonInTarget()
                    }
                    onBt2: {
                        CMaintenance.maintenanceAction(title+name2)
                        CAnimationPractice.oneButtonOutTarget()
                    }
                }
                CustomButtonIcon{
                    id:visible3_1
                    button_icon: onflag===3?"qrc:/picture/wh_jianh.png":"qrc:/picture/wh_jiah.png"
                    width: 30*dp
                    height: 30*dp
                    x:parent.width/2-15*dp
                    y:100*dp
                    onReleased: {
                        if(button_icon==="qrc:/picture/wh_jiah.png"){
                            onflag=3
                        }else{
                            onflag=0
                        }
                    }
                }
            }
            Rectangle{
                x:(parent.width-140*dp)/6*3+80*dp
                y:10*dp
                width: (parent.width-140*dp)/6
                height: parent.height-20*dp
                color: onflag===4?"#E5F0FF":"white"
                CustomDoubleButton{
                    title: "冷却设置"
                    name1: "水气全开"
                    name2: "水气全关"
                    x:20*dp
                    y:10*dp
                    width: parent.width-40*dp
                    onBt1: {
                        CMaintenance.maintenanceAction(title+name1)
                        CAnimationPractice.openPump2()
                        CAnimationPractice.openPumpHe()
                    }
                    onBt2: {
                        CMaintenance.maintenanceAction(title+name2)
                        CAnimationPractice.closePump2()
                        CAnimationPractice.closePumpHe()
                    }
                }
                CustomButtonIcon{
                    id:visible4_1
                    button_icon: onflag===4?"qrc:/picture/wh_jianh.png":"qrc:/picture/wh_jiah.png"
                    width: 30*dp
                    height: 30*dp
                    x:parent.width/2-15*dp
                    y:100*dp
                    onReleased: {
                        if(button_icon==="qrc:/picture/wh_jiah.png"){
                            onflag=4
                        }else{
                            onflag=0
                        }
                    }
                }
            }
            Rectangle{
                x:(parent.width-140*dp)/6*4+100*dp
                y:10*dp
                width: (parent.width-140*dp)/6
                height: parent.height-20*dp
                color: onflag===5?"#E5F0FF":"white"
                CustomDoubleButton{
                    inputflag: 1
                    title: "干燥时间(分)"
                    name1: "启动"
                    name2: "停止"
                    x:20*dp
                    y:10*dp
                    width: parent.width-40*dp
                    onBt1: {
                        CMaintenance.dry(inputt,"开")
                    }
                    onBt2: {
                        CMaintenance.dry(0,"关")
                    }
                }
                CustomButtonIcon{
                    id:visible5_1
                    button_icon: onflag===5?"qrc:/picture/wh_jianh.png":"qrc:/picture/wh_jiah.png"
                    width: 30*dp
                    height: 30*dp
                    x:parent.width/2-15*dp
                    y:100*dp
                    onReleased: {
                        if(button_icon==="qrc:/picture/wh_jiah.png"){
                            onflag=5
                        }else{
                            onflag=0
                        }
                    }
                }
            }
            Rectangle{
                x:(parent.width-140*dp)/6*5+120*dp
                y:10*dp
                width: (parent.width-140*dp)/6
                height: parent.height-20*dp
                color: onflag===6?"#E5F0FF":"white"
                CustomDoubleButton{
                    title: "加速端回靶"
                    name1: "启动"
                    name2: "停止"
                    x:20*dp
                    y:10*dp
                    width: parent.width-40*dp
                    onBt1: {
                        CMaintenance.maintenanceAction(title+name1)
                        CAnimationPractice.openBlowTarget()
                    }
                    onBt2: {
                        CMaintenance.maintenanceAction(title+name2)
                        CAnimationPractice.closeBlowTarget()
                    }
                }
                CustomButtonIcon{
                    id:visible6_1
                    button_icon: onflag===6?"qrc:/picture/wh_jianh.png":"qrc:/picture/wh_jiah.png"
                    width: 30*dp
                    height: 30*dp
                    x:parent.width/2-15*dp
                    y:100*dp
                    onReleased: {
                        if(button_icon==="qrc:/picture/wh_jiah.png"){
                            onflag=6
                        }else{
                            onflag=0
                        }
                    }
                }
            }
        }
        Rectangle{
            width: parent.width
            height: 230*dp
            color: "#F0F0F0"
            Rectangle{
                x:20*dp
                y:0*dp
                width: parent.width-40*dp
                height: parent.height-10*dp
                Rectangle{
                    width: parent.width
                    height: parent.height
                    CustomDoubleButton{
                        visible: visible1_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "负压阀1"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:20*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible1_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "负压阀2"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:20*dp
                        y:parent.height/2+10*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomSFourButton{
                        visible: visible3_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "进靶"
                        name1: "水冷头旋转(水平)"
                        name2: "抱闸状态-松开"
                        name3: "进靶"
                        name4: "抱闸状态-锁止"
                        x:20*dp
                        y:10*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(name1)
                            CAnimationPractice.turnWheelLeft()
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(name2)
                            CAnimationPractice.closeBrake()
                        }
                        onBt3: {
                            CMaintenance.maintenanceAction(name3)
                            CAnimationPractice.barMoveLeft()
                        }
                        onBt4: {
                            CMaintenance.maintenanceAction(name4)
                            CAnimationPractice.openBrake()
                        }
                    }
                    CustomSFourButton{
                        visible: visible3_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "退靶"
                        name1: "抱闸状态-松开"
                        name2: "退靶"
                        name3: "抱闸状态-锁止"
                        name4: "水冷头旋转(垂直)"
                        x:280*dp
                        y:10*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(name1)
                            CAnimationPractice.closeBrake()
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(name2)
                            CAnimationPractice.barMoveRight()
                        }
                        onBt3: {
                            CMaintenance.maintenanceAction(name3)
                            CAnimationPractice.openBrake()
                        }
                        onBt4: {
                            CMaintenance.maintenanceAction(name4)
                            CAnimationPractice.turnWheelDown()
                        }
                    }
                    CustomDoubleButton{
                        visible: visible4_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "水冷"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:20*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                            CAnimationPractice.openPump2()
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                            CAnimationPractice.closePump2()
                        }
                    }
                    CustomDoubleButton{
                        visible: visible4_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "气冷"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:20*dp
                        y:parent.height/2+10*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                            CAnimationPractice.openPumpHe()
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                            CAnimationPractice.closePumpHe()
                        }
                    }
                    CustomButtonIcon{
                        visible: visible4_1.button_icon==="qrc:/picture/wh_jianh.png"
                        id:visible4_2
                        button_icon: "qrc:/picture/wh_jiah.png"
                        width: 38*dp
                        height: 38*dp
                        x:(parent.width-120*dp)/5+40*dp
                        y:parent.height/4-19*dp
                        onReleased: {
                            if(button_icon==="qrc:/picture/wh_jiah.png"){
                                button_icon="qrc:/picture/wh_jianh.png"
                            }else{
                                button_icon="qrc:/picture/wh_jiah.png"
                            }
                        }
                    }
                    CustomDoubleButton{
                        visible: visible4_2.button_icon==="qrc:/picture/wh_jianh.png"&&visible4_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "水路阀2"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 3
                        x:(parent.width-120*dp)/5+100*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-30*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible4_2.button_icon==="qrc:/picture/wh_jianh.png"&&visible4_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "水路阀1"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 3
                        x:(parent.width-120*dp)/5*2+90*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-30*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible4_2.button_icon==="qrc:/picture/wh_jianh.png"&&visible4_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "水冷机"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 3
                        x:(parent.width-120*dp)/5*3+80*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-30*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomButtonIcon{
                        visible: visible4_1.button_icon==="qrc:/picture/wh_jianh.png"
                        id:visible4_3
                        button_icon: "qrc:/picture/wh_jiah.png"
                        width: 38*dp
                        height: 38*dp
                        x:(parent.width-120*dp)/5+40*dp
                        y:parent.height/4*3-19*dp
                        onReleased: {
                            if(button_icon==="qrc:/picture/wh_jiah.png"){
                                button_icon="qrc:/picture/wh_jianh.png"
                            }else{
                                button_icon="qrc:/picture/wh_jiah.png"
                            }
                        }
                    }
                    CustomDoubleButton{
                        visible: visible4_3.button_icon==="qrc:/picture/wh_jianh.png"&&visible4_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "氦气阀1"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 3
                        x:(parent.width-120*dp)/5+100*dp
                        y:parent.height/2+10*dp
                        width: (parent.width-120*dp)/5-30*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible4_3.button_icon==="qrc:/picture/wh_jianh.png"&&visible4_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "氦气阀2"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 3
                        x:(parent.width-120*dp)/5*2+90*dp
                        y:parent.height/2+10*dp
                        width: (parent.width-120*dp)/5-30*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible5_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "水路阀3"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:20*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible5_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "正压阀2"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:(parent.width-120*dp)/5+20*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible5_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "正压阀3"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:(parent.width-120*dp)/5*2+20*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible5_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "正压阀1"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:(parent.width-120*dp)/5*3+20*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible5_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "负压阀1"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:(parent.width-120*dp)/5*4+20*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible5_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "负压阀2"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:20*dp
                        y:parent.height/2+10*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible5_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "水路阀2"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:(parent.width-120*dp)/5+20*dp
                        y:parent.height/2+10*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible5_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "氦气阀1"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:(parent.width-120*dp)/5*2+20*dp
                        y:parent.height/2+10*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible5_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "氦气阀2"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:(parent.width-120*dp)/5*3+20*dp
                        y:parent.height/2+10*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible6_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "正压阀1"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:20*dp
                        y:parent.height/2-90*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                    CustomDoubleButton{
                        visible: visible6_1.button_icon==="qrc:/picture/wh_jianh.png"
                        title: "正压阀3"
                        name1: "打开"
                        name2: "关闭"
                        bttype: 2
                        x:20*dp
                        y:parent.height/2+10*dp
                        width: (parent.width-120*dp)/5-20*dp
                        onBt1: {
                            CMaintenance.maintenanceAction(title+name1)
                        }
                        onBt2: {
                            CMaintenance.maintenanceAction(title+name2)
                        }
                    }
                }
            }
        }
    }
}
